// ****************************************************************************
// *     Filename:  PrimaryGeneratorAction.cc
// *      Created:  2012-09-14 11:58:25
// *      Version:  1.0
// *     Revision:  0
// *       Author:  Tran Hoai Nam (nam), nam@kuno-g.phys.sci.osaka-u.ac.jp
// * Organization:  Osaka University
// *      License:  Geant4 Software License 
// *                http://geant4.cern.ch/license/LICENSE.html
// *  Description:  
// ****************************************************************************

#include "PrimaryGeneratorAction.hh"
#include "DetectorConstruction.hh"

#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "Randomize.hh"
#include "globals.hh"

#include "CLHEP/Random/RandFlat.h"

#include "iostream"

PrimaryGeneratorAction::PrimaryGeneratorAction() 
{; }

PrimaryGeneratorAction::~PrimaryGeneratorAction()
{
  delete fpGun;
}

PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction *det) 
	: fpDet(det)
{
  G4int n_particle = 1;
  fpGun = new G4ParticleGun(n_particle);
  fpTable = G4ParticleTable::GetParticleTable();

  fpGun->SetParticleDefinition(fpTable->FindParticle("mu-"));
  fpGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
	fpGun->SetParticleEnergy(4*MeV);
}

void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
	G4double posZ = -0.5*fpDet->Get_WorldZ();
  fpGun->SetParticlePosition(G4ThreeVector(0,0,posZ));
  fpGun->GeneratePrimaryVertex(anEvent);
}
